<template>
  <div class="resource-cont pad-bottom">
    <ul class="clear" v-loading="loading">
      <li class="resource-list fl" v-for="item of resourceList">
        <div class="resource-t clear">
          <a
            class="resource-t-l fl"
            href="javascript:;"
            @click="linkToResource(item.id)"
          >{{item.name}}.{{item.postfix}}</a>
          <div class="resource-t-r fr">
            <img :src="`${BASE_URL}/static/index/images/format/resourceicon${item.file_type}.png`" />
          </div>
        </div>
        <div class="resource-score clear">
          <div class="r-score fl clear">
            <el-rate
              v-model="item.scores_half"
              disabled
              disabled-void-color="#c5c5c5"
              text-color="#ff9900"
            ></el-rate>
            <i>{{item.scores}}</i>
          </div>
          <div class="r-collect fr">
            <i class="ipng collection08"></i>
            <strong>{{item.favs}}</strong>
          </div>
        </div>
        <div class="user-op clear">
          <div class="user-name fl">
            <span>
              <img :src="BASE_URL+item.u_avatar_path" />
            </span>
            <strong>{{item.u_name}}</strong>
          </div>
        </div>
      </li>
    </ul>
    <el-pagination
      v-if="total_sum > page_size"
      class="pageing"
      @current-change="SizeChange"
      :current-page="page_index"
      :page-size="page_size"
      layout="total, prev, pager, next,jumper"
      :total="total_sum"
    ></el-pagination>

    <!--  -->
    <div class="dependent" v-if="placeholder">
      <i class="ipng image_state01"></i>
      <p>还没发现任何相关的内容哦~</p>
    </div>
  </div>
</template>


<script>
export default {
  data() {
    return {
      page_index: 1,
      page_size: 12,
      total_sum: 0,
      resourceList: [],
      placeholder: false,
      loading: true,
      create_id: this.$route.query.id
    };
  },
  created() {
    this.getresourceList();
  },
  methods: {
    getresourceList() {
      let success = res => {
        this.resourceList = res.data.data;
        this.total_sum = parseInt(res.data.data_sum);
        this.loading = false;
        this.placeholder = this.resourceList.length === 0 ? true : false;
      };

      if (this.$g.user_id == this.$route.query.id) {
        this.$ajax.get("api/Resource/resource", {
          params: {
            create_id: this.$route.query.id,
            size: this.page_size,
            page: this.page_index,
            data_type: 2,
            status: "1,2,3"
          },
          func: { success: success }
        });
      } else {
        this.$ajax.get("api/Resource/resource", {
          params: {
            create_id: this.$route.query.id,
            size: this.page_size,
            page: this.page_index,
            data_type: 2,
            status: "1",
            authonity: 1
          },
          func: { success: success }
        });
      }
    },
    SizeChange(val) {
      this.page_index = val;
      this.getresourceList();
    },
    /*
	跳转到首页的学科资源模块查看资源
	*/
    linkToResource(resId) {
      this.$router.push({ path: "/home/resourceDetail", query: { id: resId } });
    }
  }
};
</script>